home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / FWUtil.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  10.6 KB  |  308 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWUtil.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWUTIL_H
  13. #include "FWUtil.h"
  14. #endif
  15.  
  16. #ifndef FWACQUIR_H
  17. #include "FWAcquir.h"
  18. #endif
  19.  
  20. #ifndef FWPOINT_H
  21. #include "FWPoint.h"
  22. #endif
  23.  
  24. #ifndef FWRECT_H
  25. #include "FWRect.h"
  26. #endif
  27.  
  28. #ifndef FWSESION_H
  29. #include "FWSesion.h"
  30. #endif
  31.  
  32. #ifndef FWSTRING_H
  33. #include "FWString.h"
  34. #endif
  35.  
  36. #ifndef FWMEMMGR_H
  37. #include "FWMemMgr.h"
  38. #endif
  39.  
  40. #ifndef SOM_Module_OpenDoc_Errors_defined
  41. #include <ErrorDef.xh>
  42. #endif
  43.  
  44. #ifndef SOM_ODFacet_xh
  45. #include <Facet.xh>
  46. #endif
  47.  
  48. //========================================================================================
  49. // Runtime Informations
  50. //========================================================================================
  51.  
  52. #ifdef FW_BUILD_MAC
  53. #pragma segment framework
  54. #endif
  55.  
  56. //========================================================================================
  57. // utilities
  58. //========================================================================================
  59.  
  60. //----------------------------------------------------------------------------------------
  61. //    FW_IsInLimbo
  62. //----------------------------------------------------------------------------------------
  63. // [HLX] I have to put a try block because of a bug in OpenDoc 1.0
  64.  
  65. FW_Boolean FW_IsInLimbo(Environment* ev, ODFrame* frame)
  66. {
  67.     FW_Boolean result = FALSE;
  68.     FW_TRY
  69.     {
  70.         result = frame->IsInLimbo(ev);
  71.     }
  72.     FW_CATCH_BEGIN
  73.     FW_CATCH_EVERYTHING () 
  74.     {
  75.         if (FW_GetEvError(ev) != kODErrInvalidFrame)            
  76.             FW_THROW_SAME ();
  77.     }
  78.     FW_CATCH_END    
  79.     
  80.     return result;
  81. }
  82.  
  83. //----------------------------------------------------------------------------------------
  84. //    FW_ReadODValueTypeFromStream
  85. //----------------------------------------------------------------------------------------
  86.  
  87. ODValueType FW_ReadODValueTypeFromStream(Environment* ev, FW_CReadableStream& stream)
  88. {
  89. FW_UNUSED(ev);
  90.     ODValueType typeValue;
  91.     
  92.     FW_CString aStr;
  93.     stream >> aStr;
  94.  
  95.     FW_ByteCount byteCount = aStr.GetByteLength();
  96.     typeValue = (char*)FW_CMemoryManager::AllocateBlock(byteCount + 1);
  97.     FW_CMemoryManager::CopyMemory(aStr.RevealBuffer(), typeValue, byteCount);
  98.     typeValue[byteCount] = 0;
  99.     
  100.     return typeValue;
  101. }
  102.  
  103. //----------------------------------------------------------------------------------------
  104. //    FW_ReadODTypeTokenFromStream
  105. //----------------------------------------------------------------------------------------
  106.  
  107. ODTypeToken FW_ReadODTypeTokenFromStream(Environment* ev, FW_CReadableStream& stream)
  108. {
  109.     ODValueType viewTypeValue = FW_ReadODValueTypeFromStream(ev, stream);
  110.     ODTypeToken    token = FW_CSession::Tokenize(ev, viewTypeValue);
  111.     FW_CMemoryManager::FreeBlock(viewTypeValue);
  112.     return token;
  113. }
  114.  
  115. //========================================================================================
  116. //    Content to Frame and Frame to Content coordinate conversions
  117. //========================================================================================
  118.  
  119. //----------------------------------------------------------------------------------------
  120. // FW_ContentToFrame
  121. //----------------------------------------------------------------------------------------
  122.  
  123. void FW_ContentToFrame(Environment* ev, ODFrame* frame, ODShape* shape)
  124. {
  125.     FW_CAcquiredODTransform transform = frame->AcquireInternalTransform(ev, NULL);
  126.     shape->Transform(ev, transform);
  127. }
  128.  
  129. //----------------------------------------------------------------------------------------
  130. // FW_FrameToContent
  131. //----------------------------------------------------------------------------------------
  132.  
  133. void FW_FrameToContent(Environment* ev, ODFrame* frame, ODShape* shape)
  134. {
  135.     FW_CAcquiredODTransform transform = frame->AcquireInternalTransform(ev, NULL);
  136.     shape->InverseTransform(ev, transform);
  137. }
  138.  
  139. //----------------------------------------------------------------------------------------
  140. // FW_ContentToFrame
  141. //----------------------------------------------------------------------------------------
  142.  
  143. void FW_ContentToFrame(Environment* ev, ODFrame* frame, FW_CPoint& point)
  144. {
  145.     FW_CAcquiredODTransform transform = frame->AcquireInternalTransform(ev, NULL);
  146.     point.Transform(ev, transform);
  147. }
  148.  
  149. //----------------------------------------------------------------------------------------
  150. // FW_FrameToContent
  151. //----------------------------------------------------------------------------------------
  152.  
  153. void FW_FrameToContent(Environment* ev, ODFrame* frame, FW_CPoint& point)
  154. {
  155.     FW_CAcquiredODTransform transform = frame->AcquireInternalTransform(ev, NULL);
  156.     point.InverseTransform(ev, transform);
  157. }
  158.  
  159. //----------------------------------------------------------------------------------------
  160. // FW_ContentToFrame
  161. //----------------------------------------------------------------------------------------
  162.  
  163. void FW_ContentToFrame(Environment* ev, ODFrame* frame, FW_CRect& rect)
  164. {
  165.     FW_CAcquiredODTransform transform = frame->AcquireInternalTransform(ev, NULL);
  166.     rect.Transform(ev, transform);
  167. }
  168.  
  169. //----------------------------------------------------------------------------------------
  170. // FW_FrameToContent
  171. //----------------------------------------------------------------------------------------
  172.  
  173. void FW_FrameToContent(Environment* ev, ODFrame* frame, FW_CRect& rect)
  174. {
  175.     FW_CAcquiredODTransform transform = frame->AcquireInternalTransform(ev, NULL);
  176.     rect.InverseTransform(ev, transform);
  177. }
  178.  
  179. //========================================================================================
  180. //    Content to Window and Window to Content coordinate conversions
  181. //========================================================================================
  182.  
  183. //----------------------------------------------------------------------------------------
  184. // FW_ContentToWindow
  185. //----------------------------------------------------------------------------------------
  186.  
  187. void FW_ContentToWindow(Environment* ev, ODFacet* facet, ODShape* shape)
  188. {
  189.     FW_CAcquiredODTransform transform = facet->AcquireWindowContentTransform(ev, NULL);
  190.     shape->Transform(ev, transform);
  191. }
  192.  
  193. //----------------------------------------------------------------------------------------
  194. // FW_WindowToContent
  195. //----------------------------------------------------------------------------------------
  196.  
  197. void FW_WindowToContent(Environment* ev, ODFacet* facet, ODShape* shape)
  198. {
  199.     FW_CAcquiredODTransform transform = facet->AcquireWindowContentTransform(ev, NULL);
  200.     shape->InverseTransform(ev, transform);
  201. }
  202.  
  203. //----------------------------------------------------------------------------------------
  204. // FW_ContentToWindow
  205. //----------------------------------------------------------------------------------------
  206.  
  207. void FW_ContentToWindow(Environment* ev, ODFacet* facet, FW_CPoint& point)
  208. {
  209.     FW_CAcquiredODTransform transform = facet->AcquireWindowContentTransform(ev, NULL);
  210.     point.Transform(ev, transform);
  211. }
  212.  
  213. //----------------------------------------------------------------------------------------
  214. // FW_WindowToContent
  215. //----------------------------------------------------------------------------------------
  216.  
  217. void FW_WindowToContent(Environment* ev, ODFacet* facet, FW_CPoint& point)
  218. {
  219.     FW_CAcquiredODTransform transform = facet->AcquireWindowContentTransform(ev, NULL);
  220.     point.InverseTransform(ev, transform);
  221. }
  222.  
  223. //----------------------------------------------------------------------------------------
  224. // FW_ContentToWindow
  225. //----------------------------------------------------------------------------------------
  226.  
  227. void FW_ContentToWindow(Environment* ev, ODFacet* facet, FW_CRect& rect)
  228. {
  229.     FW_CAcquiredODTransform transform = facet->AcquireWindowContentTransform(ev, NULL);
  230.     rect.Transform(ev, transform);
  231. }
  232.  
  233. //----------------------------------------------------------------------------------------
  234. // FW_WindowToContent
  235. //----------------------------------------------------------------------------------------
  236.  
  237. void FW_WindowToContent(Environment* ev, ODFacet* facet, FW_CRect& rect)
  238. {
  239.     FW_CAcquiredODTransform transform = facet->AcquireWindowContentTransform(ev, NULL);
  240.     rect.InverseTransform(ev, transform);
  241. }
  242.  
  243. //========================================================================================
  244. //    Frame to Window and Window to Frame coordinate conversions
  245. //========================================================================================
  246.  
  247. //----------------------------------------------------------------------------------------
  248. // FW_FrameToWindow
  249. //----------------------------------------------------------------------------------------
  250.  
  251. void FW_FrameToWindow(Environment* ev, ODFacet* facet, ODShape* shape)
  252. {
  253.     FW_CAcquiredODTransform transform = facet->AcquireWindowFrameTransform(ev, NULL);
  254.     shape->Transform(ev, transform);
  255. }
  256.  
  257. //----------------------------------------------------------------------------------------
  258. // FW_WindowToFrame
  259. //----------------------------------------------------------------------------------------
  260.  
  261. void FW_WindowToFrame(Environment* ev, ODFacet* facet, ODShape* shape)
  262. {
  263.     FW_CAcquiredODTransform transform = facet->AcquireWindowFrameTransform(ev, NULL);
  264.     shape->InverseTransform(ev, transform);
  265. }
  266.  
  267. //----------------------------------------------------------------------------------------
  268. // FW_FrameToWindow
  269. //----------------------------------------------------------------------------------------
  270.  
  271. void FW_FrameToWindow(Environment* ev, ODFacet* facet, FW_CPoint& point)
  272. {
  273.     FW_CAcquiredODTransform transform = facet->AcquireWindowFrameTransform(ev, NULL);
  274.     point.Transform(ev, transform);
  275. }
  276.  
  277. //----------------------------------------------------------------------------------------
  278. // FW_WindowToFrame
  279. //----------------------------------------------------------------------------------------
  280.  
  281. void FW_WindowToFrame(Environment* ev, ODFacet* facet, FW_CPoint& point)
  282. {
  283.     FW_CAcquiredODTransform transform = facet->AcquireWindowFrameTransform(ev, NULL);
  284.     point.InverseTransform(ev, transform);
  285. }
  286.  
  287. //----------------------------------------------------------------------------------------
  288. // FW_FrameToWindow
  289. //----------------------------------------------------------------------------------------
  290.  
  291. void FW_FrameToWindow(Environment* ev, ODFacet* facet, FW_CRect& rect)
  292. {
  293.     FW_CAcquiredODTransform transform = facet->AcquireWindowFrameTransform(ev, NULL);
  294.     rect.Transform(ev, transform);
  295. }
  296.  
  297. //----------------------------------------------------------------------------------------
  298. // FW_WindowToFrame
  299. //----------------------------------------------------------------------------------------
  300.  
  301. void FW_WindowToFrame(Environment* ev, ODFacet* facet, FW_CRect& rect)
  302. {
  303.     FW_CAcquiredODTransform transform = facet->AcquireWindowFrameTransform(ev, NULL);
  304.     rect.InverseTransform(ev, transform);
  305. }
  306.  
  307.  
  308.